package com.csgc.camera.biz.other.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle

import com.csgc.camera.base.BaseBindingActivity

import com.csgc.camera.events.AutoSaveImageEvents
import com.csgc.camera.events.CustomMaskEvent
import com.csgc.camera.events.ReferenceLineEvents
import com.csgc.camera.events.TakeSoundEvents
import com.csgc.camera.events.VibratingEvents
import com.csgc.camera.storage.SettingPreference
import com.csgc.camera.util.clickWithTrigger
import com.cysd.spsyxj.R
import com.cysd.spsyxj.databinding.ActivityCameraSettingBinding

import com.drake.channel.sendEvent
import com.gyf.immersionbar.ktx.immersionBar
import com.hlyj.http.ad.NewGroMoreFeedAdManager
import com.hnyyac.ad.mds.IAdView
import com.hnyyac.ad.mds.IAdViewListener
import com.hnyyac.ad.mds.manager.AdManager
import com.hnyyac.ad.mds.manager.AdManager.AdLoadListener
import com.hnyyac.ad.mds.utils.BaseAdConstants

class CameraSettingActivity:BaseBindingActivity<ActivityCameraSettingBinding>(ActivityCameraSettingBinding::inflate),IAdViewListener {

    companion object{
        fun launch(context: Context){
            context.startActivity(Intent(context,CameraSettingActivity::class.java))
        }
    }
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        immersionBar {
            fitsSystemWindows(true)

            statusBarColor(R.color.white)
            statusBarDarkFont(true)
        }

        initView()
        setListener()
        initData()
    }


    private fun initView(){
        val lineStatus = SettingPreference.instance.isReferenceLine()
        binding.sbCameraLine.isChecked = lineStatus

        val vibratingStatus = SettingPreference.instance.isCameraVibrating()
        binding.sbCameraVibrating.isChecked = vibratingStatus

        val soundStatus = SettingPreference.instance.isTakeCameraSound()
        binding.sbCameraSound.isChecked = soundStatus

        val saveStatus = SettingPreference.instance.isAutoSaveImage()
        binding.sbAutoSave.isChecked = saveStatus
    }
    private fun initData() {
        //广告插入
        val newGromoreFeedAd: NewGroMoreFeedAdManager = NewGroMoreFeedAdManager(this, BaseAdConstants.FEEDAD_Id, binding?.frameContent, 66)
        newGromoreFeedAd.loadAd()
        showDoubleChaPin()
    }
    private fun setListener(){
        binding.ivBack.clickWithTrigger { finish() }
        binding.sbCameraLine.setOnCheckedChangeListener { compoundButton, b ->
            sendEvent(ReferenceLineEvents(b))
            SettingPreference.instance.setReferenceLine(b)
        }
        binding.sbCameraVibrating.setOnCheckedChangeListener { compoundButton, b ->
            sendEvent(VibratingEvents(b))
            SettingPreference.instance.setCameraVibrating(b)
        }

        binding.sbCameraSound.setOnCheckedChangeListener { compoundButton, b ->
            sendEvent(TakeSoundEvents(b))
            SettingPreference.instance.setTakeCameraSound(b)
        }

        binding.sbAutoSave.setOnCheckedChangeListener { compoundButton, b ->
            sendEvent(AutoSaveImageEvents(b))
            SettingPreference.instance.setAutoSaveImage(b)

        }

    }

    //统一双插屏无需加位置
    fun showDoubleChaPin(){
        AdManager.loadTwoChapinSimultaneously(
            this,
            666,
            this,
            object : AdLoadListener {
                override fun onAdLoadFailed(ad: IAdView?) {

                }
            })
    }

    override fun onTrigger(adView: IAdView) {

    }

    override fun onAdShow(adView: IAdView) {

    }

    override fun onAdClick(adView: IAdView) {

    }

    override fun onAdClose(adView: IAdView) {

    }

    override fun onError(msg: String) {

    }

    override fun onLoadError(adView: IAdView) {

    }

    override fun onSuccess(adView: IAdView) {

    }

    override fun onLoad(adView: IAdView) {

    }

    override fun onSkipped() {

    }

    override fun onNoAd() {

    }

    override fun onTimeOut() {

    }


}